#include <iostream>
#include <vector>
using namespace std;

const int N = 1010;

int n, flag;
vector<int> ans;
int arr[N];

void dfs(int left, int right)
{
    if (left > right)
    {
        return;
    }
    int l = left + 1;
    int r = right;
    if (flag)
    {
        while (l <= right && arr[l] >= arr[left])
        {
            l++;
        }
        while (r > left && arr[r] < arr[left])
        {
            r--;
        }
    }
    else
    {
        while (l <= right && arr[l] < arr[left])
        {
            l++;
        }
        while (r > left && arr[r] >= arr[left])
        {
            r--;
        }
    }
    if (l - r != 1)
    {
        return;
    }
    dfs(left + 1, r);
    dfs(l, right);
    ans.push_back(arr[left]);
}

int main()
{
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> arr[i];
    }
    dfs(0, n - 1);
    if (ans.size() != n)
    {
        flag = 1;
        ans.clear();
        dfs(0, n - 1);
    }
    if (ans.size() != n)
    {
        cout << "NO" << endl;
    }
    else
    {
        cout << "YES" << endl;
        flag = 0;
        for (int i = 0; i < n; i++)
        {
            if (flag)
            {
                cout << " ";
            }
            cout << ans[i];
            flag = 1;
        }
    }
    return 0;
}